<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@page import="java.util.*"%>
<%@page import="support.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Country of Citizenship Page</title>
</head>
<body>
	<%
		//get name info from name page and set to session
		String firstName = request.getParameter("FirstName");
		session.setAttribute("FirstName", firstName);
		String lastName = request.getParameter("LastName");
		session.setAttribute("LastName", lastName);
		String middleInit = request.getParameter("MiddleI");
		session.setAttribute("MiddleI", middleInit);
	%>

	<p>
		Hello,
		<%=firstName%>
		<%=middleInit%>
		<%=lastName%>
	<p>Choose your country of citizenship:
	<form method="get" action="countryOfResident.jsp">
		<%
			//read countries from .txt file
			support s = new support();
			
			//getCountries returns a vector of the countries to be used for choosing citizenship
			Vector countries = s.getCountries();
		%>
		<table border="1">
			<%
				//print all the countries and display in 3-columns
				int i;
				for (i = 0; i < countries.size() / 3; i++) {
			%>
			<tr>
				<td><a
					href="countryOfResident.jsp?CountryOfCitizenship=<%=countries.get(i * 3)%>">
						<%
							if (i * 3 <= countries.size())
									out.println(countries.get(i * 3) + "<br>");
						%>
				</a></td>
				<td><a
					href="countryOfResident.jsp?CountryOfCitizenship=<%=countries.get(i * 3 + 1)%>">
						<%
							if (i * 3 + 1 <= countries.size())
									out.println(countries.get(i * 3 + 1) + "<br>");
						%>
				</a></td>
				<td><a
					href="countryOfResident.jsp?CountryOfCitizenship=<%=countries.get(i * 3 + 2)%>">
						<%
							if (i * 3 + 2 <= countries.size())
									out.println(countries.get(i * 3 + 2) + "<br>");
						%>
				</a></td>
			</tr>
			<%
				}
			%>
			<%
				//print the last row of  countries, if it is less than 3 columns
				if (countries.size() % 3 != 0) {
					for (i = 0; i < countries.size() % 3; i++) {
			%>
			<tr>
				<td><a
					href="countryOfResident.jsp?CountryOfCitizenship=<%=countries.get(countries.size() - 1 - i)%>">
						<%
							out.println(countries.get(countries.size() - 1 - i));
						%>
				</a></td>
			</tr>
			<%
				}
				}
			%>

		</table>
	</form>
</body>
</html>